package com.leetcodehot.problems;

public class problems704 {
    public int search(int[] nums, int target) {
        int n = nums.length;
        int left = -1;
        int right = n;
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) {
                left = mid;
            } else {
                right = mid;
            }
        }
        if (right == n) return -1;
        return nums[right] == target ? right : -1;
    }
}
